package com.nyc.boot;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Objects;

/**
 * @author niuyicong
 * @date 2025/8/25  23:42:54
 * @description
 */
public class ConditionOnClass implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 在这一块就可以根据我们特定的业务需求来决定是否注入对应的对象
        try {
            Class<?> aClass = Class.forName("com.nyc.boot.Test666");
            if (Objects.isNull(aClass)){
                return false;
            }
            return true;
        } catch (ClassNotFoundException e) {}
        return false;
    }
}




